var e = require;
var t = module;
var o = exports;
var n;
Object.defineProperty(o, "__esModule", {value: !0});
var r = e("EncryptUtil"),
    s = e("SDK"),
    c = cc._decorator,
    l = c.ccclass,
    d =
        (c.property,
        (function (e) {
            function t() {
                var t = (null !== e && e.apply(this, arguments)) || this;
                return (
                    (t._isLoaded = !1),
                    (t._url = ["http://1.116.19.93:8083/", "http://1.116.19.93:8083/", "http://1.116.19.93:8083/"]),
                    (t._isComplete = !1),
                    (t._listener = []),
                    t
                );
            }
            var o;
            return (
                __extends(t, e),
                (o = t),
                Object.defineProperty(t, "instance", {
                    get: function () {
                        return null == o._instance && (o._instance = new o()), o._instance;
                    },
                    enumerable: !1,
                    configurable: !0
                }),
                (t.prototype.log = function (e) {
                    this._config && this._config.log_enable > 0 && console.log(e);
                }),
                (t.prototype.getRandomInt = function (e, t) {
                    return Math.floor(Math.random() * Math.floor(t - e + 1)) + e;
                }),
                (t.prototype.loadPrefabs = function (e, t) {
                    this.log("**********loadPrefabs " + e);
                    var o = this;
                    cc.loader.loadRes(e, function (n, i) {
                        if (n) return cc.error(n.message || n), void o.loadPrefabs(e, t);
                        t(i);
                    });
                }),
                (t.prototype.sendPost = function (e, t, o, n) {
                    var i = !1,
                        a = this._url[s.default.Instance.edType] + e;
                    if (
                        ((this._isComplete = !1),
                        e == ["config", "config", "config"][s.default.Instance.edType] &&
                            ((i = !0), (a = this._url[s.default.Instance.edType] + e)),
                        this.log("**********net url is: " + a),
                        this.log("**********body: " + t),
                        null != a)
                    ) {
                        (t = r.EncryptUtil.en(t)), this.log("**********bodyEncrypt : " + t);
                        var c = {data: t},
                            l = JSON.stringify(c);
                        this.log("**********jsonEnData: " + l);
                        var d = this,
                            u = new XMLHttpRequest();
                        (u.onreadystatechange = function () {
                            if (4 == u.readyState && 200 == u.status) {
                                d.log("ok: " + u.response);
                                var e = JSON.parse(u.response).data;
                                if (e) {
                                    if (d._isComplete || !i) return;
                                    var t = r.EncryptUtil.de(e.data);
                                    d.log("reqR ok: " + t);
                                    var o = JSON.parse(t);
                                    (d._isComplete = !0), d.ok(o);
                                }
                            }
                        }),
                            (u.ontimeout = function () {}),
                            (u.onerror = function () {}),
                            u.open("POST", a, !0),
                            u.setRequestHeader("Content-Type", "application/json"),
                            u.setRequestHeader("gameCode", s.default.Instance.getGameCode()),
                            u.setRequestHeader("key", o),
                            u.setRequestHeader("sv", n),
                            u.send(l);
                    } else this.log("**********net url is null: " + a);
                }),
                (t.prototype.ok = function (e) {
                    (this._config = e),
                        null != e && (this._isLoaded = !0),
                        this._listener.length > 0 &&
                            this._listener.forEach(function (t) {
                                null != t && t.onOk(e);
                            });
                }),
                (t.prototype.addListener = function (e) {
                    this._listener.push(e);
                }),
                (t.prototype.isLoaded = function () {
                    return this._isLoaded;
                }),
                (t.prototype.delayShow = function (e, t) {
                    if ((this._config || (this._config = t), this._config)) {
                        var o = this._config.inser_ad_delayed_show;
                        this.log("-------delayTime: " + o);
                        var n = this._config.inser_ad_delayed_probability,
                            i = this.getRandomInt(1, 100);
                        this.log("-------delayTime random: " + i + " limitClick: " + s.default.Instance.limitClick),
                            n < i && (o = 0),
                            this.log("-------delayTime: " + o),
                            this.scheduleOnce(function () {
                                e();
                            }, o);
                    }
                }),
                (t._instance = null),
                (o = __decorate([l], t))
            );
        })(cc.Component));
o.default = d;
